import { ApiProperty } from "@nestjs/swagger";
import { Exclude } from "class-transformer";
import { ArrayMaxSize, ArrayMinSize, IsArray, IsNotEmpty, IsOptional, IsString, Length, ValidateIf } from "class-validator";

export class AuthSignInDto {
    @ApiProperty({ description: "用户名, 5-20" })
    @IsString()
    @IsNotEmpty()
    @Length(5, 20, {
        message: "用户名长度必须在$constraint1到$constraint2之间，当前传递的值是：$value",
    })
    username: string;

    @ApiProperty({ description: "密码, 6-32" })
    @IsString()
    @IsNotEmpty()
    @Length(6, 32)
    password: string;
}

export class AuthSignUpDto extends AuthSignInDto {
    @ApiProperty({ description: "确认密码, 6-32" })
    @IsString()
    @IsNotEmpty()
    @Length(6, 32)
    @ValidateIf((o: AuthSignUpDto) => o.password2 === o.password)
    password2: string;

    @Exclude()
    @IsArray()
    @ArrayMinSize(1)
    @ArrayMaxSize(3)
    @IsOptional()
    roles?: number[];
}
